package controlLayer;

import java.util.ArrayList;
import java.util.List;

import modelLayer.Subject;
import dbLayer.DBSubject;

public class SubjectCtrl {
	
	private DBSubject dbSubject = new DBSubject();
	
	public SubjectCtrl () {
		
	}
	
	public Subject findSubjectID (int subjectID) {
		
		Subject subject = null;
		
		subject = dbSubject.findSubjectID(subjectID);
		
		return subject;
		
	}
	
	public Subject findSubjectName (String subjectName) {
		
		Subject subject = null;
		
		List<Subject> resultSubjects = new ArrayList<>();
		
		resultSubjects = dbSubject.findSubjectsName(subjectName);
		
		if (resultSubjects.size() > 1) {
			System.out.println("More than one subject with that name!");
		}
		else if (resultSubjects.size() == 1) {
			subject = resultSubjects.get(0);
		}
		else {
			System.out.println("No subjects with that name!");
		}
		
		return subject;
		
	}

	public List<Subject> allSubjects() {
		return dbSubject.allSubjects();
	}

	public void addSubject(Subject subject) {
		
		dbSubject.addSubject(subject);
		
	}

	public int getHighestID() {
		
		return dbSubject.highestID();
		
	}

	public void updateSubject(Subject subject) {
		
		dbSubject.updateSubject(subject);
		
	}

	public void removeSubject(int subjectID) {
		
		dbSubject.removeSubject(subjectID);
		
	}

}
